package homework;

/**
 * @Author Stringzhua
 * @Date 2024/2/29 20:39
 * description:编程创建一个Cale计算类,在其中定义2个变量表示两个操作数
 * 定义四个方法实现求和、差、乘、商(要求除数为0的话,要提示)并创建两个对象,分别测试
 */
public class homework06 {
    public static void main(String[] args) {
        Cale cale = new Cale(2, 0);
        System.out.println("cale和 = " + cale.sum());
        System.out.println("cale差 = " + cale.minus());
        System.out.println("cale乘 = " + cale.mul());
        Double divRes = cale.div();
        if(divRes!=null) {
            System.out.println("cale除 = " + cale.div());
        }
    }
}

class Cale {
    double num1;
    double num2;

    public Cale(double num1, double num2) {
        this.num1 = num1;
        this.num2 = num2;
    }

    //和
    public double sum() {
        return num1 + num2;
    }

    //差
    public double minus() {
        return num1 - num2;
    }

    //乘
    public double mul() {
        return num1 * num2;
    }

    //除  商(要求除数为0的话,要提示)不排除0的情况会出现cale除 = Infinity
    public Double div() {
        if (num2 == 0) {
            System.out.println("你的除数(num2)不能为0");
            return null;
        } else {
            return num1 / num2;
        }
    }
}